package org.springframework.boot.netty.annotation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.boot.autoconfigure.netty.security.ShiroConfig;
import org.springframework.boot.netty.filter.JwtSecurityFilter;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * Author: huoxingzhi
 * Date: 2020/12/18
 * Email: hxz_798561819@163.com
 */
public class NettySecurityRegistrar implements ImportBeanDefinitionRegistrar {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

        registerShiroConfig(importingClassMetadata,registry);
        registerJWTLoginFilter(importingClassMetadata,registry);

    }

    private void registerShiroConfig(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry){
        RootBeanDefinition beanDefinition = new RootBeanDefinition(ShiroConfig.class);
        registry.registerBeanDefinition("shiroConfig", beanDefinition);
    }


    private void registerJWTLoginFilter(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry){
        RootBeanDefinition beanDefinition = new RootBeanDefinition(JwtSecurityFilter.class);
        registry.registerBeanDefinition("jwtSecurityFilter", beanDefinition);

    }


}
